﻿using System;
using System.Collections.Generic;
using System.Text;
using App1AppHandler;
using System.IO;
using System.Xml;

namespace Reborn_Server.App1AppHandler
{
    public class VendorItems
    {
        public long VendorCreatureID = -1;
        public string VendorName = "";
        public List<Loot> VendorSellItems = new List<Loot>();
        public List<Loot> PlayerSellItems = new List<Loot>();
        public List<Loot> BuyItems = new List<Loot>();

        public string toXML(Character sendingToCharacter)
        {
            string result = "";
            string innerXML = "";

            StringWriter stringWriter = new StringWriter();
            XmlTextWriter xmldoc = new XmlTextWriter(stringWriter);

            xmldoc.WriteStartElement("vendoritems");

            xmldoc.WriteAttributeString("VendorCreatureID", VendorCreatureID.ToString());
            xmldoc.WriteAttributeString("VendorName", VendorName.ToString());

            xmldoc.WriteStartElement("VendorSellItems");
            innerXML = "";
            foreach (Loot loot in VendorSellItems)
            {
                innerXML = innerXML + loot.toXML(sendingToCharacter);
            }
            if (innerXML != "") xmldoc.WriteRaw(innerXML);
            xmldoc.WriteEndElement();

            xmldoc.WriteStartElement("BuyItems");
            innerXML = "";
            foreach (Loot loot in BuyItems)
            {
                innerXML = innerXML + loot.toXML(sendingToCharacter);
            }
            if (innerXML != "") xmldoc.WriteRaw(innerXML);
            xmldoc.WriteEndElement();


            xmldoc.WriteEndElement();
            xmldoc.Flush();

            xmldoc.Close();

            stringWriter.Flush();

            result = stringWriter.ToString();

            return result;
        }
    }
}
